package com.primaryedu.ui.app.box;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.primaryedu.R;
import com.primaryedu.data.Contants;
import com.primaryedu.ui.BaseActivity;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 校长信箱详情
 *
 * @author jun.wang
 * @description
 * @data 2018年1月8日
 */
public class BoxDetailsActivity extends BaseActivity implements OnClickListener {

    private String mastermailId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_box_details);

        init();

    }

    @Override
    protected int BindLayout() {
        return R.layout.activity_box_details;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }


    private void init() {
        ((TextView) findViewById(R.id.title)).setText("信箱详情");
        findViewById(R.id.back).setOnClickListener(this);
        Intent intent = getIntent();
        String mastermailcontent = intent.getStringExtra("content");
        String mastermailname = intent.getStringExtra("name");
        String mastermailcreatetime = intent.getStringExtra("createtime");
        mastermailId = intent.getStringExtra("id");
        Log.i("yy", "mastermailId===========" + mastermailId);

        TextView tv_name_time = (TextView) findViewById(R.id.tv_name_time);
        tv_name_time.setText(mastermailname + "  " + mastermailcreatetime);
        TextView tv_masterboxdetails_content = (TextView) findViewById(R.id.tv_masterboxdetails_content);
        tv_masterboxdetails_content.setText(mastermailcontent);


    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.back:
//			 finish();
                detailsReadquest();
                break;

            default:
                break;
        }

    }

    private void detailsReadquest() {
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Contants.masterboxReaded,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        System.out.println("response=masterboxreaded=======" + response);
                        try {
                            JSONObject json = new JSONObject(response);
                            int result = json.getInt("result");

                            if (result == 1) {

                                Intent intent = new Intent();
                                setResult(2, intent);
                                finish();
                                String data = json.getString("data");
                                JSONObject listObj = new JSONObject(data);
                                String listStr = listObj.getString("list");

                                System.out.println("leaveLists==" + listStr);
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
//			            //在这里设置需要post的参数
//			            Map<String, String> map = new HashMap<String, String>();
//			            map.put("status", "1");
//			            map.put("pageSize", "10");
//			            map.put("pageNo", page+"") ;
//			            return map;
//					builder.append("&columnId=7f58c481e48440148472cd2cd38b7c85") ;
//					builder.append("&sord=desc") ;
                //在这里设置需要post的参数
                Map<String, String> map = new HashMap<String, String>();
//				map.put("status", "1");
                map.put("id", mastermailId);
                return map;
            }
        };
        requestQueue.add(stringRequest);
    }
}


